﻿#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QString>
#include <QTcpSocket>
#include <QMessageBox>
#include <QTimer>
#include <QTcpServer>
#include <QNetworkInterface>
#include <QUdpSocket>
#include "mythread.h"
#include <QDebug>
#include <QThreadPool>



QT_BEGIN_NAMESPACE
namespace Ui {
class Widget;
}
QT_END_NAMESPACE

class Widget : public QWidget
{
    Q_OBJECT

private:
    Ui::Widget *ui;
    QTcpSocket *client;

    enum connectStatus {
        success,
        connectting,
        notconnect
    };
    bool open_down;//1 open  0down
    connectStatus sta;
    QTimer *retryTimer;  // 新增重试定时器
    bool isbutton;
    QTcpServer *server;
    QUdpSocket *Udpsocket;

public:
    Widget(QWidget *parent = nullptr);
    ~Widget();

    void Init(QString option);
    void statusjudge(Widget::connectStatus sta);
    void Writedata(QTcpSocket *socket);
    void Readdata(QTcpSocket *socket);
    void myto_connect(QTcpSocket *socket);
    QStringList getLocalIPv4Address(void);
    void open_or_down(bool od);

private slots:
    void onIndexChanged(const QString &text);
    void clearDataSlot();
    void clearSendSlot();
    void to_connectSlot();
    void senddataSlot();
    void recvdataSlot();
    void serverRecvdata(QByteArray recvdata);
    void acceptudpslot();
signals:
    void sendsignal(QByteArray senddata);
};
#endif // WIDGET_H



